/* Copyright 2010 Michael Wenders, michaelwenders <at> gmx <dot> de

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LCMD_H_
#define LCMD_H_

#ifndef CONFIG_H
#include "lcmd_config.h"
#endif

#ifndef LCMD_MYSQL_H
#include "lcmd_mysql.h"
#endif

#ifndef LCMD_NETWORKING_H
#include "lcmd_network.h"
#endif

#include "lcmd_error.h"

class Lcmd
{
private:
	LcmdConfig *config;
	LcmdMySQL *mysqlBackend;
	LcmdNetwork *lcmdNetwork;
	lcm::log::Logger *logger;
	vector<pthread_t*> threads;

	bool runable;

	int daemonize();
	int parseCommandLine(int argc, char* argv[]);


public:
	Lcmd();
	~Lcmd();
	LcmdConfig* getConfig();
	LcmdMySQL* getMySQL();
	LcmdNetwork* getNetwork();
	lcm::log::Logger* getLogger();

	int initConfig(int argc, char* argv[]);
	int prepare();
	int check();
	int finishServer();
	int run();

	void showUsage();

	static void* handleConnection(void *arg);
	static bool quitServer;
	static void catchSignal(int sig);
};

struct connection
{
	Lcmd *lcmd;		//reference to lcmd object
	int socket;
	struct sockaddr_in *data;
};

#endif
